package com.empire.module.spider.service.lotteryfootballgamezucaibqc;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.spider.controller.app.lotteryfootballgamezucaibqc.vo.*;
import com.empire.module.spider.dal.dataobject.lotteryfootballgamezucaibqc.LotteryFootballGameZucaiBqcDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.spider.dal.mysql.lotteryfootballgamezucaibqc.LotteryFootballGameZucaiBqcMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.spider.enums.ErrorCodeConstants.*;

/**
 * 足彩6场半全场游戏 Service 实现类
 *
 * @author 无敌
 */
@Service
@Validated
public class LotteryFootballGameZucaiBqcServiceImpl implements LotteryFootballGameZucaiBqcService {

    @Resource
    private LotteryFootballGameZucaiBqcMapper lotteryFootballGameZucaiBqcMapper;

    @Override
    public String createLotteryFootballGameZucaiBqc(AppLotteryFootballGameZucaiBqcSaveReqVO createReqVO) {
        // 插入
        LotteryFootballGameZucaiBqcDO lotteryFootballGameZucaiBqc = BeanUtils.toBean(createReqVO, LotteryFootballGameZucaiBqcDO.class);
        lotteryFootballGameZucaiBqcMapper.insert(lotteryFootballGameZucaiBqc);
        // 返回
        return lotteryFootballGameZucaiBqc.getFid();
    }

    @Override
    public void updateLotteryFootballGameZucaiBqc(AppLotteryFootballGameZucaiBqcSaveReqVO updateReqVO) {
        // 校验存在
        validateLotteryFootballGameZucaiBqcExists(updateReqVO.getFid());
        // 更新
        LotteryFootballGameZucaiBqcDO updateObj = BeanUtils.toBean(updateReqVO, LotteryFootballGameZucaiBqcDO.class);
        lotteryFootballGameZucaiBqcMapper.updateById(updateObj);
    }

    @Override
    public void deleteLotteryFootballGameZucaiBqc(String id) {
        // 校验存在
        validateLotteryFootballGameZucaiBqcExists(id);
        // 删除
        lotteryFootballGameZucaiBqcMapper.deleteById(id);
    }

    private void validateLotteryFootballGameZucaiBqcExists(String id) {
        if (lotteryFootballGameZucaiBqcMapper.selectById(id) == null) {
            throw exception(LOTTERY_FOOTBALL_GAME_ZUCAI_BQC_NOT_EXISTS);
        }
    }

    @Override
    public LotteryFootballGameZucaiBqcDO getLotteryFootballGameZucaiBqc(String id) {
        return lotteryFootballGameZucaiBqcMapper.selectById(id);
    }

    @Override
    public PageResult<LotteryFootballGameZucaiBqcDO> getLotteryFootballGameZucaiBqcPage(AppLotteryFootballGameZucaiBqcPageReqVO pageReqVO) {
        return lotteryFootballGameZucaiBqcMapper.selectPage(pageReqVO);
    }

}
